using System.Threading.Tasks;
using HengTong.Model.Db.System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;

namespace HengTong.Areas._Admin.Controllers;


[AuthorizeJwtWithCookie]
public partial class SysTodoCenterController
{
    /// <summary>
    /// 获取待办事项统计数据，包括待办、已办、已协同和我的事项数量。
    /// </summary>
    /// <returns>返回包含统计数据的 <see cref="TodoStatistics"/> 对象。</returns>
    [HttpGet("GetStatistics")]
    [ActionDescription("统计数据")]
    [AllRights]
    public async Task<TodoStatistics> GetStatistics()
    {
        var statistics = new TodoStatistics
        {
            // 获取待办统计数据
            Pending = await DC.Set<SysTodoCenter>()
                .CountAsync(e => e.CreateBy == Wtm.LoginUserInfo.ITCode && e.Status == TodoStatusEnum.待办),
            Completed = await DC.Set<SysTodoCenter>()
                .CountAsync(e => e.CreateBy == Wtm.LoginUserInfo.ITCode && e.Status == TodoStatusEnum.已办),
            Collaborated = await DC.Set<SysTodoCenter>()
                .CountAsync(e => e.CreateBy == Wtm.LoginUserInfo.ITCode && e.Status == TodoStatusEnum.已协同),
            My = await DC.Set<SysTodoCenter>()
                .CountAsync(e => e.CreateBy == Wtm.LoginUserInfo.ITCode && e.Status == TodoStatusEnum.我的提交)
        };
        return statistics;
    }
    
    /// <summary>
    /// 表示待办事项的统计数据，包括待办、已办、已协同和我的事项数量。
    /// </summary>
    public class TodoStatistics
    {
        /// <summary>
        /// 待办事项数量。
        /// </summary>
        public int Pending { get; set; }

        /// <summary>
        /// 已办事项数量。
        /// </summary>
        public int Completed { get; set; }

        /// <summary>
        /// 已协同事项数量。
        /// </summary>
        public int Collaborated { get; set; }

        /// <summary>
        /// 我的事项数量。
        /// </summary>
        public int My { get; set; }
    }
}